#include "gtest/gtest.h"
#include "TurnLampModel.h"
#define LOG_TAG "TT"
#include "log_api.h"
#include "ssas_api.h"

class Test_TurnLamp : public testing::Test 
{
protected:
    static void SetUpTestCase() 
    {
    }
    static void TearDownTestCase() 
    {
    }
};


/*
COM_SID_LftTrnLmpAtv信号驱动左转向灯亮，COM_SID_RtTrnLmpAtv信号驱动左转向灯亮，如果输入信号一直不发生变化，则左转向灯每60个周期做一次亮灭

    ssas                        hmi  
     |COM_SID_LftTrnLmpAtv = 1   |
     |-------------------------->|
     |COM_SID_RtTrnLmpAtv = 0    |
     |-------------------------->|    repeat = 60
*/
TEST_F(Test_TurnLamp, testcase_testLeftTurnLampBlink)
{
    g_turnLampModelInstance.model_.init();
    
    EXPECT_EQ(WorkingData.currentState, EV_BothOff);
    EXPECT_EQ(WorkingData.leftBlinkState, 0);

    for(int i = 0; i < 60; i++)
    {
        mock_SendSIgnal(COM_SID_LftTrnLmpAtv, 1);           //模拟发送信号
        mock_SendSIgnal(COM_SID_RtTrnLmpAtv, 0);
        g_turnLampModelInstance.model_.run();
        if(i >= 0 && i < 30)
        {
            EXPECT_EQ(WorkingData.currentState, EV_LeftOn); //前30个周期左灯亮，右灯灭
            EXPECT_EQ(WorkingData.leftBlinkState, 1);
            EXPECT_EQ(WorkingData.rightBlinkState, 0);
        }
        else
        {
            EXPECT_EQ(WorkingData.currentState, EV_LeftOn); ///后30个周期左灯灭，右灯灭
            EXPECT_EQ(WorkingData.leftBlinkState, 0);
            EXPECT_EQ(WorkingData.rightBlinkState, 0);
        }
    }

    for(int i = 0; i < 60; i++)
    {
        mock_SendSIgnal(COM_SID_LftTrnLmpAtv, 1);           //模拟发送信号
        mock_SendSIgnal(COM_SID_RtTrnLmpAtv, 0);
        g_turnLampModelInstance.model_.run();
        if(i >= 0 && i < 30)
        {
            EXPECT_EQ(WorkingData.currentState, EV_LeftOn); //前30个周期左灯亮，右灯灭
            EXPECT_EQ(WorkingData.leftBlinkState, 1) << "index : " << i;
            EXPECT_EQ(WorkingData.rightBlinkState, 0);
        }
        else
        {
            EXPECT_EQ(WorkingData.currentState, EV_LeftOn); ///后30个周期左灯灭，右灯灭
            EXPECT_EQ(WorkingData.leftBlinkState, 0) << "index : " << i;
            EXPECT_EQ(WorkingData.rightBlinkState, 0);
        }
    }

}
